import QtQuick 2.0
import QtQuick.Controls 1.3
import QtQuick.Layouts 1.1
import QtQml.Models 2.2
import fan.qt.model 1.0
import "../js/mgrGoods.js" as MG
import "../lib"
FView {
    id: root
    property int downRow: 0
    function initialize()
    {

        MG.initialize();
    }

    function create(){MG.add()}
    function modify(){MG.edit()}
    function remove(){MG.remove()}

    ListModel {
        id: modelBrand
    }
    ListModel {
        id: modelCategory
    }

    FTextField {
        id: txtSearch
        title: "搜索"
        width: root.width
        height: 72 *__factor__
        iconSource: "../image/search.svg"
    }

    WorkerScript {
           id: myWorker
           source: "../js/GoodsManagerContentWorker.js"

           onMessage: {
               root.value = messageObject.value
               console.log("p:" + root.value +"->" + root.maximumValue)
           }
       }

    FTableView {
        id: tableView
        width: root.width
        height: root.height - txtSearch.height
        anchors.top: txtSearch.bottom

       model: SortFilterProxyModel {
           id: proxyModel
           source: sourceModel.count > 0 ? sourceModel : null

           sortOrder: tableView.sortIndicatorOrder
           sortCaseSensitivity: Qt.CaseInsensitive
           sortRole: sourceModel.count > 0 ? tableView.getColumn(tableView.sortIndicatorColumn).role : ""

           filterString: "*" + txtSearch.text + "*"
           ignoreRoleNames: ["Image", "Pictures"]
           filterSyntax: SortFilterProxyModel.Wildcard
           filterCaseSensitivity: Qt.CaseInsensitive
       }
       ListModel {
           id: sourceModel
       }

        TableViewColumn {
            role: "Name"; title: "标题"; width: 270 * __factor__
        }
        TableViewColumn {
            role: "CategoryAlias"; title: "分类"; width: 420* __factor__
        }

        TableViewColumn {
            role: "Stock"; title: "库存"; width: 168  * __factor__
        }

        TableViewColumn {
            role: "BrandAlias"; title: "品牌"; width: 180* __factor__
        }

        TableViewColumn {
            role: "Showcase"; title: "橱窗"; width: 100* __factor__
            delegate: Item{
                Text {
                    anchors.centerIn: parent
                    text: styleData.value ?  '是': "否"
                }
            }
        }

        TableViewColumn {
            role: "Price"; title: "单价"; width: 100* __factor__
            delegate: Item{
                Text {
                    anchors.centerIn: parent
                    text: new Number(styleData.value).toFixed(1)
                }
            }
        }

        TableViewColumn {
            role: "CreatedDateTime"; title: "创建时间"; width: 180 * __factor__
            delegate: Item{
                Text {
                    anchors.centerIn: parent
                    text: Qt.formatDate(styleData.value, "yyyy-MM-dd")
                }
            }
        }
    }
}


